package live.yanxiaohui.demo.simple;

import com.rabbitmq.client.*;
import live.yanxiaohui.demo.util.RabitMQConnection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;
/**
 * @Description 点对点通讯，推送消息后，消息自动应答
 * @CSDN https://blog.csdn.net/yxh13521338301
 * @Author yanxh<br>
 * @Date 2020/6/28 16:19<br>
 * @Version 1.0<br>
 */
public class Consumer {
    private static final String QUEUE_NAME = "game";

    public static void main(String[] args) throws IOException, TimeoutException {
        // 1.创建连接
        Connection connection = RabitMQConnection.getConnection();
        Channel channel = connection.createChannel();
        DefaultConsumer consumer = new DefaultConsumer(channel){

            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                String msg = new String(body);
                System.out.println(msg);
            }
        };
        channel.basicConsume(QUEUE_NAME, true, consumer);
        /*channel.close();
        connection.close();*/
    }
}
